package com.toman.ui.data.report;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.toman.R;
import com.umeng.analytics.MobclickAgent;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class X5Activity extends AppCompatActivity {

    @BindView(R.id.wv_base)
    WebView wvBase;
    protected boolean Landscape = true;
    String url = "http://www.zjtmcloud.com/login";
    @BindView(R.id.iv_back)
    ImageView ivBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); //设置无标题
//        getWindow().setFlags(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);  //设置全屏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_x5);
        ButterKnife.bind(this);
        init();
    }


    @SuppressLint("SetJavaScriptEnabled")
    private void init() {
        if (getIntent().getStringExtra("html") != null) {
            url = getIntent().getStringExtra("html");
        }
        wvBase.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        wvBase.loadUrl(url);

        WebSettings webSettings = wvBase.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

//        webSettings.setBlockNetworkImage(false);
//        webSettings.setBuiltInZoomControls(true);
//        webSettings.setDomStorageEnabled(true);
//        webSettings.setAppCacheMaxSize(1024*1024*20);
//        String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
//        webSettings.setAppCachePath(appCachePath);
//        webSettings.setAllowFileAccess(true);
//        webSettings.setAppCacheEnabled(true);

        wvBase.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

    }

    @Override
    protected void onResume() {
        /**
         * 设置为横屏
         */
        if (Landscape) {
            if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        } else {
            if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }
        super.onResume();
        MobclickAgent.onResume(this);

    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
